unit Imp_EtiqUsuario;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Rel, RDprint, ExtCtrls, StdCtrls, CheckLst, ComCtrls,
  Buttons, Mask, ToolEdit, CurrEdit, TFlatButtonUnit;

type
  TFrmImp_EtiqUsuario = class(TFrmPad_Rel)
    Label1: TLabel;
    ed_texto1: TEdit;
    ed_texto2: TEdit;
    ed_texto3: TEdit;
    ed_texto4: TEdit;
    ed_texto5: TEdit;
    Label2: TLabel;
    ed_qtde: TCurrencyEdit;
    p_etiqueta: TRadioGroup;
    rgCol: TRadioGroup;
    procedure ed_qtdeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Panel1Enter(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure btncancelarClick(Sender: TObject);
    procedure bimprimirClick(Sender: TObject);
    procedure RDPBeforeNewPage(Sender: TObject; Pagina: Integer);
    procedure p_etiquetaClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmImp_EtiqUsuario: TFrmImp_EtiqUsuario;

implementation

{$R *.DFM}

procedure TFrmImp_EtiqUsuario.ed_qtdeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
 if key=12 then begin
  if ed_qtde.value=0 then ed_qtde.value:= 1;
  bimprimir.enabled:= true;
 end;
end;

procedure TFrmImp_EtiqUsuario.Panel1Enter(Sender: TObject);
begin
  inherited;
 bimprimir.enabled:= true;
end;

procedure TFrmImp_EtiqUsuario.FormActivate(Sender: TObject);
begin
  inherited;
 ed_texto1.text:= '';
 ed_texto2.text:= '';
 ed_texto3.text:= '';
 ed_texto4.text:= '';
 ed_texto5.text:= '';
 ed_qtde.value := 0;
 ed_texto1.setfocus;
 p_etiqueta.ItemIndex:= 0;
end;

procedure TFrmImp_EtiqUsuario.btncancelarClick(Sender: TObject);
begin
  inherited;
 FormActivate(sender);
end;

procedure TFrmImp_EtiqUsuario.bimprimirClick(Sender: TObject);
var i: integer;
    a, colEtq: Integer;
    l: integer;
begin
  inherited;
 if trim(ed_texto1.text+ed_texto2.text+ed_texto3.text+ed_texto4.text+ed_texto5.text)<>'' then begin
  with rdp do begin
   TamanhoQteColunas:= 40;
   OpcoesPreview.PreviewZoom:= 118;
   if p_etiqueta.itemindex=0 then
    TamanhoQteLinhas:= 6
   else
    TamanhoQteLinhas:= 9;

   if (p_etiqueta.ItemIndex = 1) and (rgCol.ItemIndex = 1) then begin
    colEtq:= 0;
    a:= 0;
    TamanhoQteLinhas := 9;
    TamanhoQteColunas:= 122;
    OpcoesPreview.PreviewZoom:= 78;
   end;

   Abrir;
   for i:= 1 to ed_qtde.AsInteger do begin
    if not ((p_etiqueta.ItemIndex = 1) and (rgCol.ItemIndex = 1)) then
     if i>1 then novapagina;
    if (p_etiqueta.ItemIndex = 1) and (rgCol.ItemIndex = 1) then begin
     impf(03,colEtq+1,ed_texto1.text,[comp12]);
     impf(04,colEtq+1,ed_texto2.text,[comp12]);
     impf(05,colEtq+1,ed_texto3.text,[comp12]);
     impf(06,colEtq+1,ed_texto4.text,[comp12]);
     impf(07,colEtq+1,ed_texto5.text,[comp12]);
     inc(a);
     case a of
      1: colEtq:= 40;
      2: colEtq:= colEtq + 41;
      3: colEtq:= 999;
     end;
     if colEtq > 81 then begin
      colEtq:= 0;
      Novapagina;
      a:= 0;
     end;
    end else begin
     l:= 0;
     if (p_etiqueta.ItemIndex = 1) and (rgCol.ItemIndex = 0) then
      l:= 2;
     impf(01+l,01,ed_texto1.text,[comp12]);
     impf(02+l,01,ed_texto2.text,[comp12]);
     impf(03+l,01,ed_texto3.text,[comp12]);
     impf(04+l,01,ed_texto4.text,[comp12]);
     impf(05+l,01,ed_texto5.text,[comp12]);
    end;
   end;
   Setup;
   Fechar;
  end;
 end;
end;

procedure TFrmImp_EtiqUsuario.RDPBeforeNewPage(Sender: TObject; Pagina: Integer);
begin
  inherited;
 if rdp.Impressora=Epson then rdp.acentuacao:=SemAcento else rdp.acentuacao:=Transliterate;
end;

procedure TFrmImp_EtiqUsuario.p_etiquetaClick(Sender: TObject);
begin
  inherited;
 rgCol.Visible:= p_etiqueta.ItemIndex = 1;
end;

end.
